package main

import (
	roomServer "OemServer/internal/server/room"
	user "OemServer/internal/server/user"
	permissionServer "OemServer/internal/server/user_permission"
	role "OemServer/internal/server/user_role"
	"flag"
	"fmt"

	"OemServer/internal/config"
	oemconferenceroomserver "OemServer/internal/server/oem_conference_room"
	oemliveServer "OemServer/internal/server/oemlive"
	pointServer "OemServer/internal/server/points_info"
	room_config "OemServer/internal/server/room_config"
	"OemServer/internal/svc"
	"OemServer/pb"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

var configFile = flag.String("f", "etc/oem.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	ctx := svc.NewServiceContext(c)

	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		pb.RegisterOemLiveServer(grpcServer, oemliveServer.NewOemLiveServer(ctx))
		pb.RegisterOemConferenceRoomServer(grpcServer, oemconferenceroomserver.NewOemConferenceRoomServer(ctx))
		pb.RegisterRoomServer(grpcServer, roomServer.NewRoomServer(ctx))
		pb.RegisterUserPermissionServer(grpcServer, permissionServer.NewUserPermissionServer(ctx))
		pb.RegisterUserRoleServer(grpcServer, role.NewUserRoleServer(ctx))
		pb.RegisterUserServer(grpcServer, user.NewUserServer(ctx))
		pb.RegisterPointsInfoServer(grpcServer, pointServer.NewPointsInfoServer(ctx))
		pb.RegisterRoomConfigServer(grpcServer, room_config.NewRoomConfigServer(ctx))
		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()

	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
